
#include <stdio.h>
#include <stdlib.h>
int recursive_sum(int n)
{
	if(n == 1)
	{
		return 1;
	}
	return n + recursive_sum(n-1);
}

int main()
{
	int i = 0;
    int sum = 0;
    int n  = 10;
	while(1)
    {
		printf("请输入n值： ");
        scanf("%d", &n);
#if 0
		/*算法一*/
    	for(i=0; i<=n; i++)
    	{
			sum += i;  //O(n)
		}
#endif 
		/*算法三 递归*/
		sum = recursive_sum(n);
		printf("sum = %d\n", sum);
        sum = 0;
	}
#if 0
	/*算法二*/
    sum = (1 + n) * (n/2); //O(1)
#endif
	return 0;
}



